package AddCheckItem;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JTree;
import javax.swing.tree.TreePath;
import javax.swing.tree.DefaultTreeModel;

public class CheckBoxTreeNodeSelectionListener_ATT extends MouseAdapter
{
	@Override
	public void mouseClicked(MouseEvent event)
	{
		JTree tree = (JTree)event.getSource();
		int x = event.getX();
		int y = event.getY();
		int row = tree.getRowForLocation(x, y);
		TreePath path = tree.getPathForRow(row);		
		if(path != null)
		{
			CheckBoxTreeNode node = (CheckBoxTreeNode)path.getLastPathComponent();
			if(node != null)
			{
				boolean isSelected = !node.isSelected();
				if(isSelected){
					boolean canAdd=true;
					for(String s: AddCheck.strArr_tagAtt){
						if(s.equals(path.toString()))
							canAdd=false;						
					}
					if(canAdd)
					AddCheck.strArr_tagAtt.add(path.toString());
				}
				else {
					boolean canRemove=false;
					for(String s: AddCheck.strArr_tagAtt){
						if(s.equals(path.toString())){
							canRemove=true;
							break;
						}
					}
					if(canRemove)
					AddCheck.strArr_tagAtt.remove(path.toString());
				}
				node.setSelected(isSelected);
				((DefaultTreeModel)tree.getModel()).nodeStructureChanged(node);
			}
		}
	}
}
